package com.appbee.core.client.rpcfilter.filters;

import com.appbee.core.client.rpcfilter.RpcFilter;
import com.appbee.core.client.rpcfilter.RpcFilterChain;
import com.appbee.core.client.rpcfilter.callback.FilterCallback;


public class MinLengthFilter<I, R> implements RpcFilter<I, R>
{
	private int minLength;

	public MinLengthFilter(int minLength)
	{
		super();
		this.minLength = minLength;
	}

	@Override
	public void doFilter(I input, FilterCallback<R> callback, RpcFilterChain<I, R> chain)
	{
		String strValue = null;
		if (input instanceof String)
		{
			strValue = (String) input;
		}
		else
		{
			strValue = input.toString();
		}
		if (strValue == null || strValue.length() < minLength)
			callback.onCancel(this);
		else
			chain.doFilter(input, callback);
	}

}
